package picoevo.ext.evolution;

import java.util.ArrayList;

import picoevo.core.evolution.InitialisationOperator_Individual;
import picoevo.core.evolution.ParameterSet;
import picoevo.core.representation.Individual;
import picoevo.ext.representation.Element_Bit;
import picoevo.ext.representation.Individual_SimpleIndividual;

public class InitialisationOperator_Individual_ElementList_Bit extends InitialisationOperator_Individual {

	// ### Constructors ###

	public InitialisationOperator_Individual_ElementList_Bit() {
		super();
	}

	public InitialisationOperator_Individual_ElementList_Bit(String __name) {
		super(__name);
	}

	// ### Methods ###

	@Override
	public void initialise(Individual __o) {
		// try {
		Individual_SimpleIndividual individual = (Individual_SimpleIndividual) __o;

		// create embedded elements
		for (int k = 0; k != (individual.getTemplate()).getIntProperty("GenomeSize"); k++) {
			ArrayList OperatorList = new ArrayList();
			VariationOperator_Element_Bit_UniformMutation op = new VariationOperator_Element_Bit_UniformMutation("mutation1", (individual.getTemplate()).getDoubleProperty("MutationRate"));
			OperatorList.add(op);
			// VariationOperator_Element_DoubleZeroOneUniformMutation op2 = new
			// VariationOperator_Element_DoubleZeroOneUniformMutation
			// ("mutation2", 0.1); // add a *second* mutation operator (example
			// purpose)
			// OperatorList.add(op2);
			individual.addElement(new Element_Bit("attribute #" + k, individual, OperatorList));
		}
		for (int i = 0; i != individual.getElementListSize(); i++) {
			((Element_Bit) individual.getElementAt(i)).performInitialisation();
		}
		// this.recordAttributeListFromArrayList ( _individualList ); // must
		// do. TODO -- should be done outside this method. in super()?
		// }
		// catch ( java.lang.ClassCastException e )
		// {
		// Display.error(""+this.getClass().getName()+"::initialise(.) - Class
		// cast exception");
		// }

	}

}
